//
//  JoypadTouchControlView.h
//  iPhone SRV
//
//  Created by Nick Kitchener on 15/07/2009.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>
@class JTCState;

// simulates a joypad with touch within it.
// It does this by creating an alpha transparent interacting view and then places non-transparent touch points on it.
//

@protocol JoypadTouchControl
-(void)joypadActivated;		// joypad active
-(void)joypadValuesChanged;	// values changed (this will be a frequent call)
-(void)joypadFingerLifted;	// this can be called at any point when active indicating the users finger lifted (can be used to cancel)
-(void)joypadDeactivated;	// joypad deactivated
@end

@interface JoypadTouchControlView : UIView {
	bool		active;
	NSInteger	xValue;
	NSInteger	yValue;
	CGRect		joypadRectangle;
	JTCState	*currentState;
	CGRect		redrawRect;
}

@property(nonatomic, readwrite) NSInteger xValue;
@property(nonatomic, readwrite) NSInteger yValue;
@property(nonatomic, retain) JTCState *currentState;
@property(nonatomic, readwrite) 	CGRect		redrawRect;

-(void)setDelegate:(id <JoypadTouchControl>)delegate;

- (void)drawRect:(CGRect)rect;

-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event;
-(void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event;
-(void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event;
-(void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event;

@end

@protocol JTCStateActions
-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event;
-(void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event;
-(void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event;
-(void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event;
- (void)activationTimerFired:(NSTimer*)theTimer;
- (void)deactivationTimerFired:(NSTimer*)theTimer;
@end

@interface JTCState : NSObject <JTCStateActions> {
	JoypadTouchControlView *broker;
}
@property(nonatomic, retain) 	JoypadTouchControlView *broker;
@end

@interface JTCInactiveState : JTCState {
	NSTimer*	activationTimer;	
}
@property(nonatomic, retain) NSTimer*	activationTimer;
-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event;
-(void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event;
-(void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event;
-(void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event;
- (void)activationTimerFired:(NSTimer*)theTimer;
- (void)deactivationTimerFired:(NSTimer*)theTimer;
@end

@interface JTCActiveState : JTCState {
	NSTimer*	deactivationTimer;	
}
@property(nonatomic, retain) 	NSTimer*	deactivationTimer;
-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event;
-(void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event;
-(void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event;
-(void)touchesCancelled:(NSSet*)touches withEvent:(UIEvent*)event;
- (void)activationTimerFired:(NSTimer*)theTimer;
- (void)deactivationTimerFired:(NSTimer*)theTimer;
@end
